package com.xiaoshou.dao;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.xiaoshou.pojo.User;
import com.xiaoshou.util.EncryptPass;

@Repository
public class UserDao extends BaseDao<User, String>{

	public User verifyUser(User user) {
		String hql = "from User where username=:username and password=:password";
		Query query = getSession().createQuery(hql);
		System.out.println(user.getUsername());
		
		query.setParameter("username", user.getUsername());
		query.setParameter("password", EncryptPass.encryptPassTen(user.getPassword()));
		User currentUser= (User) query.uniqueResult();
		return currentUser;
	}

	public void updateUserPassword(User user) {
		String sql = "UPDATE `user` set `password`=:password where `id`=:id";
		Query query = getSession().createSQLQuery(sql);
		query.setParameter("password", user.getPassword());
		query.setParameter("id", user.getId());
		query.executeUpdate();
	}

	@SuppressWarnings("unchecked")
	public List<User> findLecturers() {
		String hql = "from User where role = :clinical";
		Query query = getSession().createQuery(hql);
		query.setParameter("clinical", "clinical");
		return query.list();
	}

	
	
}
